package org.myy.learn.aaa.b_双指针;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class 盛最多水的容器 {

    //核心思路： 小者，往中间走
    public static int maxArea(int[] height) {
        int n = height.length;
        int left = 0, right = n - 1;
        int maxArea = 0;
        while (left < right){
            if(height[left] > height[right]){
                maxArea = Math.max(maxArea, height[right]*(right-left));
                right --;
            } else {
                maxArea = Math.max(maxArea, height[left]*(right-left));
                left ++;
            }
        }
        return maxArea;
    }

    public static void main(String[] args) {
        int[] height = new int[]{1,8,6,2,5,4,8,3,7};
        int maxArea = maxArea(height);
        log.info("执行结束, maxArea={}", maxArea);
    }
}
